package com.youlai.boot.system.service;


import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.itextpdf.text.Document;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class PrintService {
//    private  final ExecutorService executorService = Executors.newFixedThreadPool(10);
//@Async
//    public void hadlePrintRequest(String type,String content){
//    executorService.submit(() ->{
//        try {
//            if ("pdf".equalsIgnoreCase(type)) {
//                ByteArrayOutputStream pdfStream = generatePdf(content);
//                // 假设这里有逻辑保存或者发送PDF流到客户端
//            } else if ("word".equalsIgnoreCase(type)) {
//                ByteArrayOutputStream wordStream = generateWord(content);
//                // 假设这里有逻辑保存或者发送Word流到客户端
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//    });
//    }
//
//    private ByteArrayOutputStream generatePdf(String content)throws Exception{
//         ByteArrayOutputStream  out= new ByteArrayOutputStream();
//        Document document = new Document();
//        PdfWriter.getInstance(document,out);
//        document.open();
//        document.add(new Paragraph(content));
//        document.close();
//        return out;
//    }
//    private  ByteArrayOutputStream generateWord (String content) throws Exception{
//        XWPFDocument document = new XWPFDocument();
//        XWPFParagraph paragraph = document.createParagraph();
//        paragraph.createRun().setText(content);
//        ByteArrayOutputStream out = new ByteArrayOutputStream();
//        document.write(out);
//        document.close();
//        return  out;
//
//    }
}
